<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['basic']=$return['pluginset'];
$adminuid=$return['basic']['adminuid'];
$return['isadmin']=$adminuid==$_SESSION['uid']?1:0;
if($_RQ['op']=='main'){
	$merch=pdo_get('jy_merch_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	set_html('title','会员中心');
    $member=model('core/member')->detail($_SESSION['uid'],array('id','credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	if(!$member){
		exi('找不到会员信息！','error');
	}
	$this->model('model')->checklogin();
	//是否展示审核入口
	$kefus=$return['basic']['kefus'];
	foreach($kefus as $kv){
		if($kv['mid']==$_SESSION['uid']){
			$kefu=true;
		}
	}
	if($kefu){
		$show_sh=1;
	}else{
		$show_sh=0;
	}	
	//总共收到（包含待提现）：
	$return['shenhenums']=pdo_count('jy_wechatnews_list',array('uniacid'=>$_SESSION['uniacid'],'status'=>0));
	$member['id']=$_SESSION['uid'];
	$return['member']=$member;
	$return['merch']=$merch;
	$user['avatar']=$user['avatar']?:$member['avatar'];
	$user['nickname']=$user['nickname']?:$member['nickname'];
	$return['user']=$user;
	$member['ideal_money']=pdo_getcolumn('core_ideal_money',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'money');
	$credit_types=credit_types();
	$credit_types2=array();
	foreach($credit_types as $key=>$value){
		$fee=$member['credit'.$key];
		$credit_types2[$key]=array(
			'id'=>$key,
			'title'=>$value,
			'fee'=>$fee
		);
	}
	$return['credit_types']=$credit_types2;
	$return['show_sh']=$show_sh;
	$this->setting['jifen_rate']=$this->setting['jifen_rate']?:1;
	$return['jifen_rate']=round($this->setting['jifen_rate'],2)*1;
	$return['item']=array();
	$return['post']=array();
	exi($return);
}
if($_RQ['op']=='recharge'){
	$post=get_postdata();
	if(intval($post['jifen'])<=0){
		exi('请先设置额度！并且为整数！','error');
	}
	$this->setting['jifen_rate']=$this->setting['jifen_rate']?:1;
	$jifen_rate=round($this->setting['jifen_rate'],2)*1;
	$fee=$post['jifen']/$jifen_rate;
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'couponid'=>intval($post['couponid']),
		'fee'=>$fee,
		'credit'=>$post['jifen'],
		'type'=>$post['type'],
		'createtime'=>TIMESTAMP
	);
	pdo_insert('core_recharge',$data);
	$id=pdo_insertid();
	$params=array(
		'action'=>'recharge',
		'id'=>$id,
		'fee'=>$fee,
		'title'=>'积分充值',
		'plugin'=>'core',
		//'pay_type'=>'wechat',
		'no_type'=>array('hdfk'),
		'back_url'=>'core/member.xunibi/pay_result',
		'success_url'=>'core/member.xunibi//type='.$post['type'],
		'error_url'=>'core/member.xunibi//type='.$post['type'],
	);
	if($_SESSION['container']=='aliapp' && $_SESSION['aliappopenid']){
		$params['pay_type']='alipay';
	}
	$pay_id=cfc('pay')->create_pay_order($params);
	exi($pay_id);
}
